﻿using System.Collections.Generic;
using ControleRepresentante.Logic.Models;
using WebSite.ViewModels.Fields;

namespace WebSite.ViewModels.DetailsViewModels
{
    public class RelatorioVisitaDetailsViewModel : AttributeHolderDetailsViewModel
    {
        private readonly bool m_CanViewCliente;
        private readonly bool m_CanViewVendedor;

        public RelatorioVisitaDetailsViewModel(bool canViewCliente, bool canViewVendedor)
            : base("Relatório de Visitas")
        {
            m_CanViewCliente = canViewCliente;
            m_CanViewVendedor = canViewVendedor;
        }

        protected override IEnumerable<IField> GetGeralFields()
        {
            RelatorioVisita relatorioVisita = (RelatorioVisita) Model;

            List<IField> result = new List<IField>
            {
                new LabelField("Data", "data", relatorioVisita.Data),
                m_CanViewCliente
                    ? (IField) new LinkField("Cliente", "cliente", relatorioVisita.Cliente.RazaoSocial, "Details", "Cliente", new { id = relatorioVisita.Cliente.Id})
                    : new LabelField("Cliente", "cliente", relatorioVisita.Cliente.RazaoSocial),
                m_CanViewVendedor
                    ? (IField) new LinkField("Vendedor", "vendedor", relatorioVisita.Vendedor.Nome, "Details", "Vendedor", new { id = relatorioVisita.Vendedor.Id})
                    : new LabelField("Vendedor", "vendedor", relatorioVisita.Vendedor.Nome),
                new LabelField("Observação", "observacao", relatorioVisita.Observacao)
            };
            result.AddRange(base.GetGeralFields());
            return result;
        }
    }
}